package cn.gjxblog.modules.sys.controller;

import cn.gjxblog.common.model.HttpResult;
import cn.gjxblog.common.model.PageInfo;
import cn.gjxblog.common.model.PageRequest;
import cn.gjxblog.modules.sys.entity.SysRoleEntity;
import cn.gjxblog.modules.sys.service.SysRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;




/**
 * 角色
 *
 * @author guojiaxun
 * @date 2019-09-17 11:28:40
 */
@RestController
@RequestMapping("sys/sysrole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @ApiOperation("获取列表")
    public HttpResult<PageInfo> list(@RequestBody PageRequest pageRequest){
        PageInfo pageInfo = sysRoleService.searchList(pageRequest);
        return HttpResult.ok(pageInfo);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{roleId}")
    @ApiOperation("获取信息")
    public HttpResult info(@PathVariable("roleId") Long roleId){
		SysRoleEntity sysRole = sysRoleService.getById(roleId);

        return HttpResult.ok(sysRole);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存信息")
    public HttpResult save(@RequestBody SysRoleEntity sysRole){
		sysRoleService.save(sysRole);

        return HttpResult.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改信息")
    public HttpResult update(@RequestBody SysRoleEntity sysRole){
		sysRoleService.updateById(sysRole);

        return HttpResult.ok();
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    @ApiOperation("删除信息")
    public HttpResult delete(@RequestBody Long[] roleIds){
		sysRoleService.removeByIds(Arrays.asList(roleIds));
        return HttpResult.ok();
    }

}
